package org.ligson.spark.rdd.demo;

import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function2;
import org.ligson.spark.util.SparkContextUtil;

import java.util.Arrays;

public class ReduceTest {
    public static void main(String[] args) {
        JavaSparkContext context = SparkContextUtil.getLocalContext();
        JavaRDD<Integer> rdd = context.parallelize(Arrays.asList(new Integer[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}));
        int result = rdd.reduce(new Function2<Integer, Integer, Integer>() {
            public Integer call(Integer pre, Integer after) throws Exception {
                return pre + after;
            }
        });
        System.out.println(result);

    }
}
